﻿namespace PublicStaticClass.UIControl
{
    using Bll.Systems;
    using System;
    using System.Web.UI;
    using System.Windows.Forms;

    public class WindowBase : Form
    {
        public void CheckPopedom(Page page, string[] CheckPopName, string[] checkPopIsUse)
        {
            PopedomCheck.CheckPopName = CheckPopName;
            PopedomCheck.checkPopIsUse = checkPopIsUse;
            PopedomCheck.checkRolePopeDom();
        }

        public void CheckPopedom(Form forms, DataGridView DataGridList, string[] CheckPopName, string[] checkPopIsUse)
        {
            if (ConfigBll.GetModel(1).IsUseMeUse != 1)
            {
                PopedomCheckWindows.CheckPopName = CheckPopName;
                PopedomCheckWindows.checkPopIsUse = checkPopIsUse;
                PopedomCheckWindows.checkRolePopeDom();
                Button button = new Button();
                int count = DataGridList.Columns.Count;
                if (checkPopIsUse.Length >= 3)
                {
                    Exception exception;
                    try
                    {
                        if (checkPopIsUse[0] != "1")
                        {
                            ((Panel) this.findLastControl(this, "btnAddNew")).Visible = false;
                        }
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                    }
                    try
                    {
                        if (checkPopIsUse[1] != "1")
                        {
                            DataGridList.Columns[count - 2].Visible = false;
                        }
                    }
                    catch (Exception exception2)
                    {
                        exception = exception2;
                    }
                    try
                    {
                        if (checkPopIsUse[2] != "1")
                        {
                            ((Panel) this.findLastControl(this, "btnDelele")).Visible = false;
                            DataGridList.Columns[count - 1].Visible = false;
                        }
                    }
                    catch (Exception exception3)
                    {
                        exception = exception3;
                    }
                }
            }
        }

        public void ClearCntrValue(System.Windows.Forms.Control parContainer)
        {
            for (int i = 0; i < parContainer.Controls.Count; i++)
            {
                if (parContainer.Controls[i].HasChildren)
                {
                    this.ClearCntrValue(parContainer.Controls[i]);
                }
                else
                {
                    string name = parContainer.Controls[i].GetType().Name;
                    if (name != null)
                    {
                        if (!(name == "TextBox"))
                        {
                            if (name == "RadioButton")
                            {
                                goto Label_00A8;
                            }
                            if (name == "CheckBox")
                            {
                                goto Label_00C2;
                            }
                            if (name == "ComboBox")
                            {
                                goto Label_00DC;
                            }
                        }
                        else
                        {
                            parContainer.Controls[i].Text = "";
                        }
                    }
                }
                continue;
            Label_00A8:
                ((RadioButton) parContainer.Controls[i]).Checked = false;
                continue;
            Label_00C2:
                ((CheckBox) parContainer.Controls[i]).Checked = false;
                continue;
            Label_00DC:
                ((ComboBox) parContainer.Controls[i]).Text = "";
            }
        }

        public System.Windows.Forms.Control findControl(System.Windows.Forms.Control control, string controlName)
        {
            foreach (System.Windows.Forms.Control control3 in control.Controls)
            {
                if (control3.Name == controlName)
                {
                    return control;
                }
                if (control3.Controls.Count > 0)
                {
                    System.Windows.Forms.Control control2 = this.findControl(control3, controlName);
                    if (control2 != null)
                    {
                        return control2;
                    }
                }
            }
            return null;
        }

        public System.Windows.Forms.Control findLastControl(System.Windows.Forms.Control control, string controlName)
        {
            foreach (System.Windows.Forms.Control control3 in control.Controls)
            {
                if (control3.Name == controlName)
                {
                    return control;
                }
                if (control3.Controls.Count > 0)
                {
                    System.Windows.Forms.Control control2 = this.findControl(control3, controlName);
                    if (control2 != null)
                    {
                        return control2;
                    }
                }
            }
            return null;
        }

        public void nextKeyControl(string nextKey)
        {
            System.Windows.Forms.Control control = this.findLastControl(this, nextKey);
            control.Select();
            control.Focus();
        }
    }
}

